package com.hbu.ware.hbumallware.controller;

import com.hbu.common.utils.PageUtils;
import com.hbu.common.utils.R;
import com.hbu.ware.hbumallware.entity.WareSkuEntity;
import com.hbu.ware.hbumallware.service.WareSkuService;
import com.hbu.ware.hbumallware.vo.WareSkuListVO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;


/**
 * 商品库存
 *
 * @author zhaoxiaohan
 * @email 13315217827@163.com
 * @date 2022-10-28 12:04:52
 */
@RestController
@RequestMapping("ware/waresku")
@AllArgsConstructor
public class WareSkuController {

    private WareSkuService wareSkuService;

    /**
     * 列表
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public R list(WareSkuListVO wareSkuListVO) {
        PageUtils page = wareSkuService.getList(wareSkuListVO);

        return R.ok().put("page", page);
    }

    @RequestMapping(value = "/getSkuStockStatus/{skuId}", method = RequestMethod.GET)
    public Boolean getSkuStockStatus(@PathVariable Long skuId) {
        return wareSkuService.getSkuStockStatus(skuId);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        WareSkuEntity wareSku = wareSkuService.getById(id);

        return R.ok().put("wareSku", wareSku);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody WareSkuEntity wareSku) {
        wareSkuService.save(wareSku);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody WareSkuEntity wareSku) {
        wareSkuService.updateById(wareSku);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        wareSkuService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
